package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-09-20
 * Time: 10:23
 */
public class ThreadDemon13 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
           while(!Thread.currentThread().isInterrupted()){ //当t1.interrupt();生效，循环条件为false，被打断了
               try {
                   Thread.sleep(500);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("t1线程正在运行");
           }
        });

        t1.start();
        Thread.sleep(2001);
        t1.interrupt();//让t1被打断，相当于isQuit = true
        System.out.println("终止t1线程");

    }
}
